﻿using System;
using FubarDev.FtpServer.AccountManagement;
using Microsoft.Extensions.Configuration;

namespace Hicap.QRCodeWarehouse.Processor.FtpServer
{
    public class BasicUserMembershipProvider : IMembershipProvider
    {
        private readonly string _username;
        private readonly string _password;

        public BasicUserMembershipProvider(IConfiguration configuration)
        {
            _username = configuration["DefaultAuthorizationUser:UserName"];
            _password = configuration["DefaultAuthorizationUser:Password"];
        }

        public MemberValidationResult ValidateUser(string username, string password)
        {
            if (username != null && username.Equals(this._username, StringComparison.InvariantCultureIgnoreCase))
            {
                if (password != null && _password.Equals(password))
                    return new MemberValidationResult(MemberValidationStatus.AuthenticatedUser, new CustomFtpUser(username));
            }
            return new MemberValidationResult(MemberValidationStatus.InvalidLogin);
        }
    }
}